import request from '@/utils/request'

export function getPermissionList(query) {
  return request({
    url: '/system/permission/search',
    method: 'get',
    params: query
  })
}

// 保存，传复杂对象，参数用data
export function savePermission(permission) {
  return request({
    url: '/system/permission/save',
    method: 'post',
    data: permission
  })
}

// 获取权限菜单节点
export function getPermissionTree(query) {
  return request({
    url: '/system/permission/getPermissionTreeEnterprise',
    method: 'get',
    params: query
  })
}
// 获取权限菜单节点
export function getPermissionTreeBySearch(query) {
  return request({
    url: '/system/permission/getPermissionTreeBySearch',
    method: 'get',
    params: query
  })
}

// 获取当前用户菜单
export function getCurrentPermissions(query) {
  return request({
    url: '/system/permission/getCurrentPermissions',
    method: 'get',
    params: query
  })
}

// 排序
export function setSortOrder(query) {
  return request({
    url: '/system/permission/sortOrder',
    method: 'get',
    params: query
  })
}

// 删除
export function deletePermission(permissionId) {
  if (!permissionId) {
    return false
  }
  return request({
    url: '/system/permission/delete',
    method: 'get',
    params: { permissionId }
  })
}

/**
 * 获取当前角色的某个权限的子权限id列表
 *
 * @param roleId       当前角色id
 * @param permissionId 指定权限id
 * @return 子节点权限id列表
 */
export function getPermissionIds(roleId, permissionId) {
  if (!roleId || !permissionId) {
    return false
  }
  return request({
    url: '/system/permission/getPermissionIds',
    method: 'get',
    params: {
      roleId,
      permissionId
    }
  })
}

/**
 * 获取当前权限的子节点权限列表
 *
 * @param permissionId 当前权限id
 * @return 子节点权限列表
 */
export function getChildren(permissionId) {
  if (!permissionId) {
    return false
  }
  return request({
    url: '/system/permission/getChildren',
    method: 'get',
    params: {
      permissionId
    }
  })
}
